package com.ply.flashsalessystem.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ply.flashsalessystem.entity.pojo.JionRepositoryDetails;
import com.ply.flashsalessystem.entity.vo.manage.JoinRepositoryDetailsVo;
import com.ply.flashsalessystem.entity.wrapper.JoinRepositoryDetailsWrapper;
import com.ply.flashsalessystem.mapper.JionRepositoryDetailsMapper;
import com.ply.flashsalessystem.service.JionRepositoryDetailsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author XiaoPan
 * @since 2022-03-23
 */
@Service
public class JionRepositoryDetailsServiceImpl extends ServiceImpl<JionRepositoryDetailsMapper, JionRepositoryDetails> implements JionRepositoryDetailsService {
    @Autowired
    JionRepositoryDetailsMapper jionRepositoryDetailsMapper;

    /**
     * 商品 入库 详情
     * @param jionRepositoryDetails 必须 有商品 id 入库id
     */
    @Override
    public boolean addJoinRepositoryDetails(JionRepositoryDetails jionRepositoryDetails) {
        //判断商品 的数量 和 花费的 总金额 不允许 为负数
        if (jionRepositoryDetails.getNums() < 0 || jionRepositoryDetails.getAllCost() < 0) {
            return false;
        }
        return jionRepositoryDetailsMapper.insert(jionRepositoryDetails) != 0;
    }



    @Override
    public boolean addJoinRepositoryDetailsMany(Long manageId, List<JionRepositoryDetails> jionRepositoryDetails) {
        return false;
    }




    @Override
    public Page<JoinRepositoryDetailsVo> queryJoinRepositoryDetails(Integer current, Integer limit, JoinRepositoryDetailsWrapper joinRepositoryDetailsWrapper) {
        return jionRepositoryDetailsMapper.queryJoinRepositoryDetails(new Page<>(current,limit),joinRepositoryDetailsWrapper);
    }
}
